package model

import (
	"strconv"
	"zimuzu_cvn_web_api/lib/grpcClient"
	. "zimuzu_cvn_web_api/pkg/e"
	"zimuzu_cvn_web_api/pkg/errno"
)

type DbSign struct {
	SignString  string `db:"sign_string" json:"sign_string"`
	SignVersion string `db:"sign_version" json:"sign_version"`
}

//校验数据库签名
func CheckCvnDbSign(uid int64) (ok bool, err error) {
	//校验账户签名
	request := map[string]string{
		"uid": strconv.FormatInt(uid, 10),
	}
	amountCheckResponse, err := grpcClient.CvnAmountCheck(request)
	if err != nil {
		return false, err
	}
	if !amountCheckResponse.Ok {
		Log("err", errno.DbSignError)
		return false, nil
	}
	//校验流水签名
	logListCheckResponse, err := grpcClient.CvnLogListCheck(request)
	if err != nil {
		return false, err
	}
	if logListCheckResponse.ErrNum > 0 {
		Log("err", errno.DbSignError)
		return false, nil
	}
	return true, nil
}

//校验数据库签名
func CheckUsdtDbSign(uid int64) (ok bool, err error) {
	//校验账户签名
	request := map[string]string{
		"uid": strconv.FormatInt(uid, 10),
	}
	amountCheckResponse, err := grpcClient.UsdtAmountCheck(request)
	if err != nil {
		return false, err
	}
	if !amountCheckResponse.Ok {
		Log("err", errno.DbSignError)
		return false, nil
	}
	//校验流水签名
	logListCheckResponse, err := grpcClient.UsdtLogListCheck(request)
	if err != nil {
		return false, err
	}
	if logListCheckResponse.ErrNum > 0 {
		Log("err", errno.DbSignError)
		return false, nil
	}
	return true, nil
}
